package com.banciyuan.wallpaper.base.app;

import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.banciyuan.wallpaper.constants.Constants;
import com.tencent.bugly.crashreport.CrashReport;

/**
 * Created by squall on 2016/5/11.
 */
public class BaseApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        initBugly();
    }

    private void initBugly() {

        try {
            CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext()); //App的策略Bean
            ApplicationInfo appInfo = this.getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
            String qqChannel = appInfo.metaData.getString("QQCrash_CHANNEL");
            if (!TextUtils.isEmpty(qqChannel)) strategy.setAppChannel(qqChannel);     //设置渠道
            else strategy = null;
            if (strategy == null) {
                CrashReport.initCrashReport(this, Constants.CRASH_APP_ID, false);
            } else {
                CrashReport.initCrashReport(this, Constants.CRASH_APP_ID, false, strategy);
            }
            TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
            String imei = telephonyManager.getDeviceId();
            if (!TextUtils.isEmpty(imei)) {
                CrashReport.setUserId(imei);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
